package com.lzm.handle;

import com.lzm.dto.ResultDto;
import com.lzm.exception.SeckillException;
import com.lzm.utils.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResultDto handle(Exception e) {
        if(e instanceof SeckillException) {
            return ResultUtil.error(e.getMessage());
        }else {
            return ResultUtil.error(e.getMessage());
        }
    }

}
